<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="module-test.html" />
<link rel="parent" href="development.html" />
<link rel="next" href="module-pdb.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>23.5 test.test_support -- Utility functions for tests</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="23.4.2 running tests using"
  href="regrtest.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="23. development Tools"
  href="development.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="24. the Python Debugger"
  href="module-pdb.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="regrtest.html">23.4.2 Running tests using</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="development.html">23. Development Tools</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-pdb.html">24. The Python Debugger</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION0025500000000000000000">
23.5 <tt class="module">test.test_support</tt> --
         Utility functions for tests</a>
</h1>

<p>
<a name="module-test.testsupport"></a>

<p>
The <tt class="module">test.test_support</tt> module provides support for Python's
regression tests.

<p>
This module defines the following exceptions:

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-5061' xml:id='l2h-5061' class="exception">TestFailed</tt></b></dt>
<dd>
Exception to be raised when a test fails.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-5062' xml:id='l2h-5062' class="exception">TestSkipped</tt></b></dt>
<dd>
Subclass of <tt class="exception">TestFailed</tt>.
Raised when a test is skipped.
This occurs when a needed resource (such as a network connection) is not
available at the time of testing.
</dd></dl>

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-5063' xml:id='l2h-5063' class="exception">ResourceDenied</tt></b></dt>
<dd>
Subclass of <tt class="exception">TestSkipped</tt>.
Raised when a resource (such as a network connection) is not available.
Raised by the <tt class="function">requires()</tt> function.
</dd></dl>

<p>
The <tt class="module">test.test_support</tt> module defines the following constants:

<p>
<dl><dt><b><tt id='l2h-5064' xml:id='l2h-5064'>verbose</tt></b></dt>
<dd>
<tt class="constant">True</tt> when verbose output is enabled.
Should be checked when more detailed information is desired about a running
test.
<var>verbose</var> is set by <tt class="module">test.regrtest</tt>.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5065' xml:id='l2h-5065'>have_unicode</tt></b></dt>
<dd>
<tt class="constant">True</tt> when Unicode support is available.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5066' xml:id='l2h-5066'>is_jython</tt></b></dt>
<dd>
<tt class="constant">True</tt> if the running interpreter is Jython.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5067' xml:id='l2h-5067'>TESTFN</tt></b></dt>
<dd>
Set to the path that a temporary file may be created at.
Any temporary that is created should be closed and unlinked (removed).
</dd></dl>

<p>
The <tt class="module">test.test_support</tt> module defines the following functions:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5068' xml:id='l2h-5068' class="function">forget</tt></b>(</nobr></td>
  <td><var>module_name</var>)</td></tr></table></dt>
<dd>
Removes the module named <var>module_name</var> from <code>sys.modules</code> and deletes
any byte-compiled files of the module.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5069' xml:id='l2h-5069' class="function">is_resource_enabled</tt></b>(</nobr></td>
  <td><var>resource</var>)</td></tr></table></dt>
<dd>
Returns <tt class="constant">True</tt> if <var>resource</var> is enabled and available.
The list of available resources is only set when <tt class="module">test.regrtest</tt>
is executing the tests.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5070' xml:id='l2h-5070' class="function">requires</tt></b>(</nobr></td>
  <td><var>resource</var><big>[</big><var>, msg</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Raises <tt class="exception">ResourceDenied</tt> if <var>resource</var> is not available.
<var>msg</var> is the argument to <tt class="exception">ResourceDenied</tt> if it is raised.
Always returns true if called by a function whose <code>__name__</code> is
<code>'__main__'</code>.
Used when tests are executed by <tt class="module">test.regrtest</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5071' xml:id='l2h-5071' class="function">findfile</tt></b>(</nobr></td>
  <td><var>filename</var>)</td></tr></table></dt>
<dd>
Return the path to the file named <var>filename</var>.
If no match is found <var>filename</var> is returned.
This does not equal a failure since it could be the path to the file.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5072' xml:id='l2h-5072' class="function">run_unittest</tt></b>(</nobr></td>
  <td><var>*classes</var>)</td></tr></table></dt>
<dd>
Execute <tt class="class">unittest.TestCase</tt> subclasses passed to the function.
The function scans the classes for methods starting with the prefix
"<tt class="samp">test_</tt>" and executes the tests individually.
This is the preferred way to execute tests.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5073' xml:id='l2h-5073' class="function">run_suite</tt></b>(</nobr></td>
  <td><var>suite</var><big>[</big><var>, testclass</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Execute the <tt class="class">unittest.TestSuite</tt> instance <var>suite</var>.
The optional argument <var>testclass</var> accepts one of the test classes in the
suite so as to print out more detailed information on where the testing suite
originated from.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="23.4.2 running tests using"
  href="regrtest.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="23. development Tools"
  href="development.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="24. the Python Debugger"
  href="module-pdb.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="regrtest.html">23.4.2 Running tests using</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="development.html">23. Development Tools</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-pdb.html">24. The Python Debugger</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
